﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditAsset.aspx.cs" Inherits="HRProject.Asset.EditAsset" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Edit an Asset</title>
    <link href="/css/jsDatePick_ltr.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" language="javascript" src="/js/jquery-1.8.2.js"></script>
    <script type="text/javascript" language="javascript" src="/js/jsDatePick.min.1.3.js"></script>
    <script type="text/javascript">
	window.onload = function(){
		new JsDatePick({
			useMode:2,
			target:"tbxImportDate",
			dateFormat:"%d/%m/%Y"
		});
		new JsDatePick({
			useMode:2,
			target:"tbxTerminateDate",
			dateFormat:"%d/%m/%Y"
		});
		
		var obj = window.dialogArguments;
		$("#tbxName").val(obj.name);
	    $("#tbxProductId").val(obj.productId);
	    $("#txaDescription").val(obj.description);
	    $("#tbxImportDate").val(obj.importDate);
	    $("#tbxTerminateDate").val(obj.terminateDate);
	    $("#hdfImageUrl").val(obj.imageUrl);
	    $("#imgAsset").attr("src", obj.imageUrl);
	};
	
	function submitAsset(){
	    if (jQuery.trim($("#tbxName").val()) == "")
	    {
	        $("#lblError").html("Invalid asset name");
	        return;
	    }
	    window.returnValue=getAssetInfo();
	    window.close();
	}
	
	function getAssetInfo(){
	    var obj = new Object();
	    obj.name = jQuery.trim($("#tbxName").val());
	    obj.productId = jQuery.trim($("#tbxProductId").val());
	    obj.description = jQuery.trim($("#txaDescription").val());
	    obj.importDate = jQuery.trim($("#tbxImportDate").val());
	    obj.terminateDate = jQuery.trim($("#tbxTerminateDate").val());
	    obj.imageUrl = jQuery.trim($("#hdfImageUrl").val());
	    return obj;
	}
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <table>
            <tr>
                <td>Name</td>
                <td><asp:TextBox ID="tbxName" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Product ID</td>
                <td><asp:TextBox ID="tbxProductId" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Import date</td>
                <td><asp:TextBox ID="tbxImportDate" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Terminate date</td>
                <td><asp:TextBox ID="tbxTerminateDate" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Description</td>
                <td><asp:TextBox ID="txaDescription" runat="server" TextMode="MultiLine"></asp:TextBox></td>
            </tr>
            <tr>
                <td><asp:CheckBox ID="cbxIcon" runat="server" Text="Image"/></td>
                <td>
                    <asp:FileUpload ID="fulIcon" runat="server"/>
                    <asp:Button ID="btnUpload" runat="server" Text="Upload" 
                        onclick="btnUpload_Click"/><br />
                    <asp:Image ID="imgAsset" runat="server" Width="100" Height="100"/>
                    <asp:HiddenField ID="hdfImageUrl" runat="server" />
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="Add" onclick="submitAsset();" />
                    <input type="button" name="btnCancel" value="Cancel"
                        onclick="window.returnValue='cancel';window.close();"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:Label ID="lblError" runat="server" Text="" ForeColor="Red"></asp:Label>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
